package com.csot.interceptor;

import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpMethod;
import org.springframework.ui.ModelMap;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.context.request.WebRequestInterceptor;

import com.csot.queue.QueueHolder;
import com.csot.service.CitySegmentDelete;
import com.csot.service.CitySegmentDetail;
import com.csot.service.CoarseSegmentDelete;
import com.csot.service.IdleIpService;
import com.csot.service.IndexService;
import com.csot.service.IpCoarseSegmentDetail;
import com.csot.service.TotalSegmentDelete;
import com.csot.service.TotalSegmentDetail;

public class IpInjectInterceptor implements WebRequestInterceptor {

    @Override
    public void preHandle(WebRequest request) throws Exception {
        // TODO Auto-generated method stub
        // ThreadLocal<Map<String, Object>> t = ThreadUtil.createThreadLocal(false);
    }

    @Override
    public void postHandle(WebRequest request, ModelMap model) throws Exception {
        // TODO Auto-generated method stub
//        if (request instanceof ServletWebRequest) {
//            ServletWebRequest swr = ((ServletWebRequest) request);
//            HttpMethod hm = swr.getHttpMethod();
//            String uri = swr.getRequest().getRequestURI();
//            switch (hm.name().toLowerCase()) {
//                case "put":
//                    if (StringUtils.contains(uri, "citysegment")) {
//                        if (!StringUtils.contains(uri, "importQuery"))
//                            QueueHolder.offer(new CitySegmentDetail());
//                    }
//                    QueueHolder.offer(new IndexService());
//                    break;
//                case "delete":
//                    if (StringUtils.contains(uri, "citysegment")) {
//                        QueueHolder.offer(new CitySegmentDelete());
//                    }
//                    if (StringUtils.contains(uri, "totalsegment")) {
//                        QueueHolder.offer(new TotalSegmentDelete());
//                    }
//                    if (StringUtils.contains(uri, "coarsesegment")) {
//                        QueueHolder.offer(new CoarseSegmentDelete());
//                    }
//                    QueueHolder.offer(new IndexService());
//                    break;
//                case "post":
//                    if (StringUtils.contains(uri, "citysegment")) {
//                        if (!StringUtils.contains(uri, "importQuery"))
//                            QueueHolder.offer(new CitySegmentDetail());
//                    }
//                    if (StringUtils.contains(uri, "coarsesegment")) {
//                        QueueHolder.offer(new IpCoarseSegmentDetail());
//                    }
//                    //totalsegment
////                    if (StringUtils.contains(uri, "totalsegment")) {
////                        QueueHolder.offer(new IpCoarseSegmentDetail());
////                    }
//
//                    QueueHolder.offer(new IndexService());
//                    break;
//            }
//        }

    }

    @Override
    public void afterCompletion(WebRequest request, Exception ex) throws Exception {
        // TODO Auto-generated method stub

    }

}
